package main;
import java.io.*;
import java.util.*;

import analysis.parser.*;
import analysis.syntaxtree.*;
import analysis.symboltable.*;
import analysis.typechecker.*;

public class Main {
	private static String sourceFile;
	private static String sourceName;
	private static Properties config;

	public static void main(String[] args) throws Exception {


		sourceFile = args[0];
		int p = sourceFile.lastIndexOf('.');
		sourceName = sourceFile.substring(0, p);

		new Parser(new FileInputStream(sourceFile));


		Program program = null;

		try {
			System.out.println("Parsing ...");
			program = Parser.Goal();
		}
		catch (ParseException e) {
			System.out.println(e.getMessage());
			return;
		}

		SymbolTableBuilderVisitor symtBuilder = new SymbolTableBuilderVisitor();
		TypeCheckerVisitor typeChecker = new TypeCheckerVisitor();

		System.out.println("Building symbol table ...");
		program.accept(symtBuilder);

		System.out.println("Typechecking ...");
		program.accept(typeChecker);

		System.out.println("\nDone!");
	}


}
